package com.example.ac36;

/**
 * @description 构建Trie树，字符集只包含 a-z 这26个字符
 * @auther lijiewei
 * @date 2022/1/19 17:11
 */
public class Trie {

    /**
     * 往 Trie 树中插入一个字符串
     * @param root 根节点
     * @param text 字符串
     * @return
     * @author lijiewei
     * @date   2022/1/19 17:15
     */
    public void insert(AcNode root, char[] text) {
        AcNode p = root;
        for (int i = 0; i < text.length; i++) {
            int index = text[i] - 'a';
            if (p.children[index] == null) {
                AcNode newNode = new AcNode(text[i]);
                p.children[index] = newNode;
            }
            p = p.children[index];
        }
        p.isEndingChar = true;
        p.length = text.length;
    }
}
